import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref({
      token: '',
      userId: ''
    })

    const setUserInfo = (obj) => {
      userInfo.value = obj
    }

    const logout = () => {
      userInfo.value = {
        token: '',
        userId: ''
      }
    }

    return {
      userInfo, setUserInfo, logout
    }
  },
  {
    persist: {
      key: 'user', // 指定存储的 key
      storage: localStorage // 指定存储方式，默认是 localStorage
    }
  }
)
